
Ext.namespace("Microtraining.Admin.Test");
Mt = Microtraining.Admin;
Mt.Test={
  /**
   * 全局配置
   */
  Config:{
  /**
   *分页:每页显示记录数
   */
  PageSize:15,
  /**
   *显示配置
   */
  View:{
    /**
     * 显示考试的视图相对考试列表Grid的位置
     * 1:上方,2:下方,3:左侧,4:右侧,
     */
    Direction:2,
    /**
     *是否显示。
     */
    IsShow:0,
    /**
     * 是否固定显示考试信息页(或者打开新窗口)
     */
    IsFix:0
  },
    /**
     * 在线编辑器类型。
     * 1:CkEditor,2:KindEditor,3:xhEditor
     * 配合Action的变量配置$online_editor
     */
    OnlineEditor:1
  },
  /**
   * Cookie设置
   */
  Cookie:new Ext.state.CookieProvider(),
  /**
   * 初始化
   */
  Init:function(){
  if (Mt.Test.Cookie.get('View.Direction')){
    Mt.Test.Config.View.Direction=Mt.Test.Cookie.get('View.Direction');
  }
  if (Mt.Test.Cookie.get('View.IsFix')!=null){
    Mt.Test.Config.View.IsFix=Mt.Test.Cookie.get('View.IsFix');
  }
    if (Ext.util.Cookies.get('OnlineEditor')!=null){
      Mt.Test.Config.OnlineEditor=parseInt(Ext.util.Cookies.get('OnlineEditor'));
    }

  }
};
/**
 * Model:数据模型
 */
Mt.Test.Store = {
  /**
   * 考试
   */
  testStore:new Ext.data.Store({
  reader: new Ext.data.JsonReader({
    totalProperty: 'totalCount',
    successProperty: 'success',
    root: 'data',remoteSort: true,
    fields : [
        {name: 'test_id',type: 'int'},
        {name: 'company_id',type: 'int'},
        {name: 'company_name',type: 'string'},
        {name: 'admin_name',type: 'string'},
        {name: 'test_title',type: 'string'},
        {name: 'paper_id',type: 'int'},
        {name: 'paper_title',type: 'string'},
        {name: 'paper_json',type: 'string'},
        {name: 'paper_jsonShow',type:'string'},
        {name: 'begin_time',type: 'date',dateFormat:'Y-m-d H:i:s'},
        {name: 'end_time',type: 'date',dateFormat:'Y-m-d H:i:s'},
        {name: 'isShow',type: 'string'},
        {name: 'memberStr',type: 'string'}
    ]}
  ),
  writer: new Ext.data.JsonWriter({
    encode: false
  }),
  listeners : {
    beforeload : function(store, options) {
    if (Ext.isReady) {
      if (!options.params.limit)options.params.limit=Mt.Test.Config.PageSize;
      Ext.apply(options.params, Mt.Test.View.Running.testGrid.filter);//保证分页也将查询条件带上
    }
    }
  }
  }),
  /**
   * 企业
   */
  companyStoreForCombo:new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: 'home/admin/src/httpdata/company.php'
    }),
    reader: new Ext.data.JsonReader({
      root: 'companys',
      autoLoad: true,
      totalProperty: 'totalCount',
      idProperty: 'company_id'
    }, [
      {name: 'company_id', mapping: 'company_id'},
      {name: 'company_name', mapping: 'company_name'}
    ])
  }),
  /**
   * 试卷
   */
  paperStoreForCombo:new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: 'home/admin/src/httpdata/paper.php'
    }),
    reader: new Ext.data.JsonReader({
      root: 'papers',
      autoLoad: true,
      totalProperty: 'totalCount',
      idProperty: 'paper_id'
    }, [
      {name: 'paper_id', mapping: 'paper_id'},
      {name: 'paper_title', mapping: 'paper_title'}
    ])
  }),
  /**
   * 会员考试
   */
  mtestStore:new Ext.data.Store({
    reader: new Ext.data.JsonReader({
      totalProperty: 'totalCount',
      successProperty: 'success',
      root: 'data',remoteSort: true,
      fields : [
        {name: 'mtest_id',type: 'int'},
        {name: 'company_name',type: 'string'},
        {name: 'admin_name',type: 'string'},
        {name: 'username',type: 'string'},
        {name: 'department_name',type: 'string'},
        {name: 'position_name',type: 'string'},
        {name: 'area_name',type: 'string'},
        {name: 'test_title',type: 'string'},
        {name: 'score',type: 'int'},
        {name: 'answers_json',type: 'int'}
      ]}
    ),
    writer: new Ext.data.JsonWriter({
      encode: false 
    }),
    listeners : {
      beforeload : function(store, options) {
        if (Ext.isReady) {
          if (!options.params.limit)options.params.limit=Mt.Test.Config.PageSize;
          Ext.apply(options.params, Mt.Test.View.Running.mtestGrid.filter);//保证分页也将查询条件带上
        }
      }
    }
  }),
  /**
   * 会员
   */
  selectMemberStore:new Ext.data.Store({
    reader: new Ext.data.JsonReader({
      totalProperty: 'totalCount',
      successProperty: 'success',
      root: 'data',remoteSort: true,
      fields : [
        {name: 'member_id',type: 'int'},
        {name: 'company_id',type: 'int'},
        {name: 'company_name',type: 'string'},
        {name: 'department_id',type: 'int'},
        {name: 'department_name',type: 'string'},
        {name: 'position_id',type: 'int'},
        {name: 'position_name',type: 'string'},
        {name: 'area_id',type: 'int'},
        {name: 'area_name',type: 'string'},
        {name: 'username',type: 'string'},
        {name: 'password',type: 'string'},
        {name: 'realname',type: 'string'},
        {name: 'code',type: 'string'},
        {name: 'tel',type: 'string'},
        {name: 'email',type: 'string'},
        {name: 'qq',type: 'string'},
        {name: 'weixin',type: 'string'},
        {name: 'icon_image',type: 'string'},
        {name: 'point',type: 'float'}
      ]}
    ),
    writer: new Ext.data.JsonWriter({
      encode: false
    }),
    listeners : {
      beforeload : function(store, options) {
        if (Ext.isReady) {
          Ext.apply(options.params, Mt.Test.View.Running.selectMemberWindow.memberGrid.filter);//保证分页也将查询条件带上
        }
      },
      load : function(records,options){
        if (records&&records.data&&records.data.items) {
          var selData  = Mt.Test.View.Running.selectMemberWindow.selData;//选中的会员
          var data     = records.data.items;
          //把已经推荐的会员选中
          var sm=Mt.Test.View.Running.selectMemberWindow.memberGrid.sm;
          var rows=Mt.Test.View.Running.selectMemberWindow.memberGrid.getView().getRows();
          for(var i=0;i<rows.length;i++){
            if(selData[data[i]['data'].member_id]){
              sm.selectRow(i, true);
            }
          }
        }
      }
    }
  }),
  /**
   * 企业
   */
  companyStoreForCombo:new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: 'home/admin/src/httpdata/company.php'
    }),
    reader: new Ext.data.JsonReader({
      root: 'companys',
      autoLoad: true,
      totalProperty: 'totalCount',
      idProperty: 'company_id'
    }, [
      {name: 'company_id', mapping: 'company_id'},
      {name: 'company_name', mapping: 'company_name'}
    ])
  }),
  /**
   * 部门
   */
  departmentStoreForCombo:new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: 'home/admin/src/httpdata/department.php'
    }),
    reader: new Ext.data.JsonReader({
      root: 'departments',
      autoLoad: true,
      totalProperty: 'totalCount',
      idProperty: 'department_id'
    }, [
      {name: 'department_id', mapping: 'department_id'},
      {name: 'department_name', mapping: 'department_name'}
    ])
  }),
  /**
   * 职位
   */
  positionStoreForCombo:new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: 'home/admin/src/httpdata/position.php'
    }),
    reader: new Ext.data.JsonReader({
      root: 'positions',
      autoLoad: true,
      totalProperty: 'totalCount',
      idProperty: 'position_id'
    }, [
      {name: 'position_id', mapping: 'position_id'},
      {name: 'position_name', mapping: 'position_name'}
    ])
  }),
  /**
   * 地区
   */
  areaStoreForCombo:new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: 'home/admin/src/httpdata/area.php'
    }),
    reader: new Ext.data.JsonReader({
      root: 'areas',
      autoLoad: true,
      totalProperty: 'totalCount',
      idProperty: 'area_id'
    }, [
      {name: 'area_id', mapping: 'area_id'},
      {name: 'area_name', mapping: 'area_name'}
    ])
  }),
  /**
   * 会员
   */
  memberStoreForCombo:new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
      url: 'home/admin/src/httpdata/member.php'
    }),
    reader: new Ext.data.JsonReader({
      root: 'members',
      autoLoad: true,
      totalProperty: 'totalCount',
      idProperty: 'member_id'
    }, [
      {name: 'member_id', mapping: 'member_id'},
      {name: 'username', mapping: 'username'}
    ])
  })
};
/**
 * View:考试显示组件
 */
Mt.Test.View={
  /**
   * 编辑窗口：新建或者修改考试
   */
  EditWindow:Ext.extend(Ext.Window,{
  constructor : function(config) {
    config = Ext.apply({
    /**
     * 自定义类型:保存类型
     * 0:保存窗口,1:修改窗口
     */
    savetype:0,
    closeAction : "hide",
    constrainHeader:true,maximizable: true,collapsible: true,
    width : 450,height : 550,minWidth : 400,minHeight : 450,
    layout : 'fit',plain : true,buttonAlign : 'center',
    defaults : {
      autoScroll : true
    },
    listeners:{
      beforehide:function(){
      this.editForm.form.getEl().dom.reset();
      },
          afterrender:function(){ 
          }
    },
    items : [
      new Ext.form.FormPanel({
      ref:'editForm',layout:'form',
      labelWidth : 100,labelAlign : "center",
      bodyStyle : 'padding:5px 5px 0',align : "center",
      api : {},
      defaults : {
        xtype : 'textfield',anchor:'98%'
      },
      items : [
              {xtype: 'hidden',name : 'test_id',ref:'../test_id'},
              // {xtype: 'hidden',name : 'company_id',ref:'../company_id'},
              /*{
                 fieldLabel : '企业',xtype: 'combo',name : 'company_name',ref : '../company_name',
                 store:Mt.Test.Store.companyStoreForCombo,emptyText: '请选择企业',itemSelector: 'div.search-item',
                 loadingText: '查询中...',width: 570, pageSize:Mt.Test.Config.PageSize,
                 displayField:'company_name',grid:this,
                 mode: 'remote',  editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                 forceSelection: true,triggerAction: 'all',resizable:false,selectOnFocus:true,
                 tpl:new Ext.XTemplate(
                   '<tpl for="."><div class="search-item">',
                     '<h3>{company_name}</h3>',
                   '</div></tpl>'
                 ),
                 listeners:{
                   'beforequery': function(event){delete event.combo.lastQuery;}
                 },
                 onSelect:function(record,index){
                   if(this.fireEvent('beforeselect', this, record, index) !== false){
                    this.grid.company_id.setValue(record.data.company_id);
                    this.grid.company_name.setValue(record.data.company_name);
                    this.collapse();
                   }
                 }
              },*/
              {fieldLabel : '考试名称',name : 'test_title'},
              {xtype: 'hidden',name : 'paper_id',ref:'../paper_id'},
              {
                 fieldLabel : '试卷',xtype: 'combo',name : 'paper_title',ref : '../paper_title',
                 store:Mt.Test.Store.paperStoreForCombo,emptyText: '请选择试卷',itemSelector: 'div.search-item',
                 loadingText: '查询中...',width: 570, pageSize:Mt.Test.Config.PageSize,
                 displayField:'paper_title',grid:this,
                 mode: 'remote',  editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                 forceSelection: true,triggerAction: 'all',resizable:false,selectOnFocus:true,
                 tpl:new Ext.XTemplate(
                   '<tpl for="."><div class="search-item">',
                     '<h3>{paper_title}</h3>',
                   '</div></tpl>'
                 ),
                 listeners:{
                   'beforequery': function(event){delete event.combo.lastQuery;}
                 },
                 onSelect:function(record,index){
                   if(this.fireEvent('beforeselect', this, record, index) !== false){
                    this.grid.paper_id.setValue(record.data.paper_id);
                    this.grid.paper_title.setValue(record.data.paper_title);
                    this.collapse();
                   }
                 }
              },
              {xtype: 'hidden',name : 'paper_json',ref:'../paper_json'},
              // {fieldLabel : '考试试卷',name : 'paper_json',xtype : 'textarea',id:'paper_json',ref:'paper_json'},
              {fieldLabel : '开考时间',name : 'begin_time',ref:'../begin_time',xtype : 'datefield',format : "Y-m-d H:i:s"},
              {fieldLabel : '交卷时间',name : 'end_time',ref:'../end_time',xtype : 'datefield',format : "Y-m-d H:i:s"},
              {fieldLabel : '是否显示',hiddenName : 'isShow'
                 ,xtype:'combo',ref:'../isShow',mode : 'local',triggerAction : 'all',
                 lazyRender : true,editable: false,allowBlank : false,valueNotFoundText:'否',
                 store : new Ext.data.SimpleStore({
                   fields : ['value', 'text'],
                   data : [['0', '否'], ['1', '是']]
                 }),emptyText: '请选择是否显示',
                 valueField : 'value',displayField : 'text'
              }
      ]
      })
    ],
    buttons : [{
      text: "",ref : "../saveBtn",scope:this,
      handler : function() {
        if (!this.editForm.getForm().isValid()) {
          return;
        }

        var now = new Date();
        var str=now.getFullYear()+'-'+(now.getMonth()+1)+'-'+now.getDate();
        var today = new Date(str).getTime();

        var etime=this.end_time.getValue();
        var btime=this.begin_time.getValue();
        // if (etime.getTime() <= btime.getTime()) {
        //   Ext.Msg.alert('提示','结束时间不能小于开始时间');
        //   return;
        // }
        // if (etime.getDate() != btime.getDate()) {
        //   Ext.Msg.alert('提示','结束时间和开始时间需在同一天');
        //   return;
        // };

        editWindow=this;
        if (this.savetype==0){
          this.editForm.api.submit=ExtServiceTest.save;
          this.editForm.getForm().submit({
          success : function(form, action) {
            Ext.Msg.alert("提示", "保存成功！");
            Mt.Test.View.Running.testGrid.doSelectTest();
            form.reset();
            editWindow.hide();
          },
          failure : function(form, response) {
            Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
          }
          });
        }else{
          this.editForm.api.submit=ExtServiceTest.update;
          this.editForm.getForm().submit({
          success : function(form, action) {
            Mt.Test.View.Running.testGrid.store.reload();
            Ext.Msg.show({title:'提示',msg: '修改成功！',buttons: {yes: '确定'},fn: function(){
            Mt.Test.View.Running.testGrid.bottomToolbar.doRefresh();
            }});
            form.reset();
            editWindow.hide();
          },
          failure : function(form, response) {
            Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
          }
          });
        }
      }
    }, {
      text : "取 消",scope:this,
      handler : function() {
      this.hide();
      }
    }, {
      text : "重 置",ref:'../resetBtn',scope:this,
      handler : function() {
      this.editForm.form.loadRecord(Mt.Test.View.Running.testGrid.getSelectionModel().getSelected());
            // switch (Mt.Test.Config.OnlineEditor)
            // {
            //   case 2:
            //     if (Mt.Test.View.EditWindow.KindEditor_paper_json) Mt.Test.View.EditWindow.KindEditor_paper_json.html(Mt.Test.View.Running.testGrid.getSelectionModel().getSelected().data.paper_json);
            //     break
            //   case 3:
            //     break
            //   default:
            //     if (CKEDITOR.instances.paper_json) CKEDITOR.instances.paper_json.setData(Mt.Test.View.Running.testGrid.getSelectionModel().getSelected().data.paper_json);
            // }

      }
    }]
    }, config);
    Mt.Test.View.EditWindow.superclass.constructor.call(this, config);
  }
  }),
  /**
   * 显示考试详情
   */
  TestView:{
  /**
   * Tab页：容器包含显示与考试所有相关的信息
   */
  Tabs:Ext.extend(Ext.TabPanel,{
    constructor : function(config) {
    config = Ext.apply({
      region : 'south',collapseMode : 'mini',split : true,
      activeTab: 1, tabPosition:"bottom",resizeTabs : true,
      header:false,enableTabScroll : true,tabWidth:'auto', margins : '0 3 3 0',
      defaults : {
      autoScroll : true,
      layout:'fit'
      },
      listeners:{
      beforetabchange:function(tabs,newtab,currentTab){
        if (tabs.tabFix==newtab){
        if (Mt.Test.View.Running.testGrid.getSelectionModel().getSelected()==null){
          Ext.Msg.alert('提示', '请先选择考试！');
          return false;
        }
        Mt.Test.Config.View.IsShow=1;
        Mt.Test.View.Running.testGrid.showTest();
        Mt.Test.View.Running.testGrid.tvpView.menu.mBind.setChecked(false);
        return false;
        }
      }
      },
      items: [
      {title:'+',tabTip:'取消固定',ref:'tabFix',iconCls:'icon-fix'}
      ]
    }, config);
    Mt.Test.View.TestView.Tabs.superclass.constructor.call(this, config);
        Mt.Test.View.Running.mtestGrid=new Mt.Test.View.MtestView.Grid();
    this.onAddItems();
    },
    /**
     * 根据布局调整Tabs的宽度或者高度以及折叠
     */
    enableCollapse:function(){
    if ((Mt.Test.Config.View.Direction==1)||(Mt.Test.Config.View.Direction==2)){
      this.width =Ext.getBody().getViewSize().width;
      this.height=Ext.getBody().getViewSize().height/2;
    }else{
      this.width =Ext.getBody().getViewSize().width/2;
      this.height=Ext.getBody().getViewSize().height;
    }
    this.ownerCt.setSize(this.width,this.height);
    if (this.ownerCt.collapsed)this.ownerCt.expand();
    this.ownerCt.collapsed=false;
    },
    onAddItems:function(){
    this.add(
      {title: '基本信息',ref:'tabTestDetail',iconCls:'tabs',
       tpl: [
       '<table class="viewdoblock">',
             '  <tr class="entry"><td class="head">所属用户</td><td class="content">{admin_name}</td></tr>',
             '  <tr class="entry"><td class="head">考试名称</td><td class="content">{test_title}</td></tr>',
             '  <tr class="entry"><td class="head">试卷</td><td class="content">{paper_title}</td></tr>',
             // '  <tr class="entry"><td class="head">考试试卷</td><td class="content">{paper_jsonShow}</td></tr>',
             '  <tr class="entry"><td class="head">开考时间</td><td class="content">{begin_time:date("Y-m-d")}</td></tr>',
             '  <tr class="entry"><td class="head">交卷时间</td><td class="content">{end_time:date("Y-m-d")}</td></tr>',
       '</table>'
       ]}
    );
        this.add(
          {title: '考试成绩',iconCls:'tabs',tabWidth:150,
           items:[Mt.Test.View.Running.mtestGrid]
          }
        );
    }
  }),
  /**
   * 窗口:显示考试信息
   */
  Window:Ext.extend(Ext.Window,{
    constructor : function(config) {
    config = Ext.apply({
      title:"查看考试",constrainHeader:true,maximizable: true,minimizable : true,
      width : 705,height : 500,minWidth : 450,minHeight : 400,
      layout : 'fit',resizable:true,plain : true,bodyStyle : 'padding:5px;',
      closeAction : "hide",
      items:[new Mt.Test.View.TestView.Tabs({ref:'winTabs',tabPosition:'top'})],
      listeners: {
      minimize:function(w){
        w.hide();
        Mt.Test.Config.View.IsShow=0;
        Mt.Test.View.Running.testGrid.tvpView.menu.mBind.setChecked(true);
      },
      hide:function(w){
        Mt.Test.View.Running.testGrid.tvpView.toggle(false);
      }
      },
      buttons: [{
      text: '新增考试',scope:this,
      handler : function() {this.hide();Mt.Test.View.Running.testGrid.addTest();}
      },{
      text: '修改考试',scope:this,
      handler : function() {this.hide();Mt.Test.View.Running.testGrid.updateTest();}
      }]
    }, config);
    Mt.Test.View.TestView.Window.superclass.constructor.call(this, config);
    }
  })
  },
  /**
   * 视图：会员
   */
  MemberView:{
    SelectMemberWindow:Ext.extend(Ext.Window,{
      constructor : function(config) {
        config = Ext.apply({
          selData:null,//选中的会员
          oldData:null,//已关联的会员
          title:"选择会员",updateData:null,closeAction:"hide",constrainHeader:true,maximizable:true,collapsible:true,
          width:720,minWidth:720,height:560,minHeight:450,layout:'fit',plain : true,buttonAlign : 'center',
          defaults : {autoScroll : true,},
          listeners:{
            beforehide:this.doHide
          },
          items : [new Mt.Test.View.MemberView.MemberGrid({ref:"memberGrid"})],
          buttons : [ {
            text: "确定",ref : "../saveBtn",scope:this,
            handler : function() {
              var selData = this.selData;
              var oldData = this.oldData;
              //考试标识
              var test_id=Mt.Test.View.Running.testGrid.getSelectionModel().getSelected().data.test_id;
              var condition={'selData':selData,"oldData":oldData,"test_id":test_id};
              Ext.Msg.show({
                title: '请等待', msg: '操作进行中，请稍后...',
                animEl: 'loading', icon: Ext.Msg.WARNING,
                closable: true, progress: true, progressText: '', width: 300
              });
              ExtServiceTest.updateTestMember(condition,function(provider, response) {
                if (response.result.success==true) {
                  var msg = "操作成功！";
                  if(response.result.del){
                    msg += "<font color=red>取消</font>了<font color=red>"+response.result.del+"</font>个关联会员,";
                  }
                  if(response.result.add){
                    msg += "<font color=green>添加</font>了<font color=green>"+response.result.add+"</font>个关联会员";
                  }
                  Ext.Msg.alert('提示', msg);
                } else {
                  Mt.Test.Store.selectMemberStore.removeAll();
                  Ext.Msg.alert('提示', response.result.msg);
                }
                Mt.Test.View.Running.selectMemberWindow.hideWindow();
                Mt.Test.View.Running.testGrid.doSelectTest();
              });
            }
          }, {
            text : "取 消",scope:this,
            handler : function() {
              this.hide();
            }
          }]
        }, config);
        Mt.Test.View.MemberView.SelectMemberWindow.superclass.constructor.call(this, config);
      },
      /**
      * 根据选择的会员,改变标题
      */
      changeTitle: function(){
        var title   = "选择 会员";
        var selData = this.selData;
        var count   = this.objElCount(selData);
        if(count){
          title += "（已经选择了<font color=green>"+count+"</font>件会员）";
        }else{
          title += "（尚未选择任何会员）";
        }
        this.setTitle(title);
      },
      /**
      * 判断自定义对象元素个数
      */
      objElCount: function(obj){
        var count = 0;
        for(var n in obj){count++}
        return count;
      },
      /**
       * 确认取消图片处理
       * con:选择窗口
       */
      doHide: function (con) {
        //window初始化时会调用,此时con为null
        if(con){
          Ext.MessageBox.show({
            title:'提示',msg:'确定要取消么?<br /><font color=red>(所做操作将不会保存!)</font>',buttons:Ext.MessageBox.YESNO,icon:Ext.MessageBox.QUESTION,
            params:{con:con},
            fn:function(btn,text,opt) {
              if(btn=='yes') {
                con.hideWindow();
              }
            }
          });
          return false;
        }
      },
      /**
       * 隐藏窗口
       */
      hideWindow: function () {
        //移除beforehide事件，为了防止hide时进入死循环
        this.un('beforehide',this.doHide);
        this.hide();
        this.addListener('beforehide',this.doHide);
      }
    }),
    MemberGrid:Ext.extend(Ext.grid.GridPanel,{
      constructor : function(config) {
        config = Ext.apply({
          /**
           * 查询条件
           */
          filter:null,test_id:null,region : 'center',store : Mt.Test.Store.selectMemberStore,sm : this.sm,
          trackMouseOver : true,enableColumnMove : true,columnLines : true,loadMask : true,stripeRows : true,headerAsText : false,
          loadMask : {msg : '加载数据中，请稍候...'},
          defaults : {autoScroll : true},
          cm : new Ext.grid.ColumnModel({
            defaults:{width:120,sortable : true},
            columns : [
              this.sm,
              {header : '标识',dataIndex : 'member_id',hidden:true},
              {header : '公司',dataIndex : 'company_name'},
              {header : '部门',dataIndex : 'department_name'},
              {header : '职位',dataIndex : 'position_name'},
              {header : '地区',dataIndex : 'area_name'},
              {header : '用户名',dataIndex : 'username'},
              {header : '姓名',dataIndex : 'realname'},
              {header : '员工号',dataIndex : 'code'}/*,
              {header : '电话',dataIndex : 'tel'},
              {header : 'email',dataIndex : 'email'},
              {header : 'qq',dataIndex : 'qq'},
              {header : '微信',dataIndex : 'weixin'},
              {header : '积分',dataIndex : 'point'}*/
            ]
          }),
          tbar : {
            xtype : 'container',layout : 'anchor',
            height : 27,style:'font-size:14px',
            defaults : {
              height : 27,anchor : '100%'
            },
            items : [
              new Ext.Toolbar({
                enableOverflow: true,width : 80,ref:'menus',
                defaults : {
                  xtype : 'textfield',
                  listeners : {
                     specialkey : function(field, e) {
                      if (e.getKey() == Ext.EventObject.ENTER)this.ownerCt.ownerCt.ownerCt.doSelectMember();
                    }
                  }
                },
                items : [
                  {text: '全部',ref:'../../isSelect',xtype:'tbsplit',iconCls : 'icon-view',enableToggle: true,
                     toggleHandler:function(item, checked){
                      if (checked==true){
                        Mt.Test.View.Running.selectMemberWindow.memberGrid.topToolbar.menus.select.setChecked(true);
                      }else{
                        Mt.Test.View.Running.selectMemberWindow.memberGrid.topToolbar.menus.all.setChecked(true);
                      }
                    },
                    menu: {
                      items: [
                        {text: '全部',checked: true,group: 'isSelect',ref:'../../all',
                          checkHandler: function(item, checked){
                            if (checked){
                              Mt.Test.View.Running.selectMemberWindow.memberGrid.isSelect.setText(item.text);
                              Mt.Test.View.Running.selectMemberWindow.memberGrid.filter.selectType=0;
                            }
                            Mt.Test.View.Running.selectMemberWindow.memberGrid.doSelectMember();
                          }
                        },
                        {text: '未选择',checked: false,group: 'isSelect',ref:'../../unselect',
                            checkHandler: function(item, checked){
                              if (checked){
                                Mt.Test.View.Running.selectMemberWindow.memberGrid.isSelect.setText(item.text);
                                Mt.Test.View.Running.selectMemberWindow.memberGrid.filter.selectType=2;
                              }
                              Mt.Test.View.Running.selectMemberWindow.memberGrid.doSelectMember();
                            }
                        },
                        {text: '已选择',checked: false,group: 'isSelect',ref:'../../select',
                            checkHandler: function(item, checked){
                              if (checked){
                                Mt.Test.View.Running.selectMemberWindow.memberGrid.isSelect.setText(item.text);
                                Mt.Test.View.Running.selectMemberWindow.memberGrid.filter.selectType=1;
                              }
                              Mt.Test.View.Running.selectMemberWindow.memberGrid.doSelectMember();
                          }
                        }
                       ]
                    }
                  },
                  /*'公司','&nbsp;&nbsp;',{ref: '../mcompany_id',xtype: 'combo',
                     store:Mt.Test.Store.companyStoreForCombo,hiddenName : 'company_id',
                     emptyText: '请选择公司',itemSelector: 'div.search-item',
                     loadingText: '查询中...',width:280,pageSize:Mt.Test.Config.PageSize,
                     displayField:'company_name',valueField:'company_id',
                     mode: 'remote',editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                     forceSelection: true,triggerAction: 'all',resizable:true,selectOnFocus:true,
                     tpl:new Ext.XTemplate(
                       '<tpl for="."><div class="search-item">',
                       '<h3>{company_name}</h3>',
                       '</div></tpl>'
                     )
                  },'&nbsp;&nbsp;',*/
                  '部门','&nbsp;&nbsp;',{ref: '../mdepartment_id',xtype: 'combo',
                     store:Mt.Test.Store.departmentStoreForCombo,hiddenName : 'department_id',
                     emptyText: '请选择部门',itemSelector: 'div.search-item',
                     loadingText: '查询中...',width:100,pageSize:Mt.Test.Config.PageSize,
                     displayField:'department_name',valueField:'department_id',
                     mode: 'remote',editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                     forceSelection: true,triggerAction: 'all',resizable:true,selectOnFocus:true,
                     tpl:new Ext.XTemplate(
                       '<tpl for="."><div class="search-item">',
                       '<h3>{department_name}</h3>',
                       '</div></tpl>'
                     )
                  },'&nbsp;&nbsp;',
                  '职位','&nbsp;&nbsp;',{ref: '../mposition_id',xtype: 'combo',
                     store:Mt.Test.Store.positionStoreForCombo,hiddenName : 'position_id',
                     emptyText: '请选择职位',itemSelector: 'div.search-item',
                     loadingText: '查询中...',width:100,pageSize:Mt.Test.Config.PageSize,
                     displayField:'position_name',valueField:'position_id',
                     mode: 'remote',editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                     forceSelection: true,triggerAction: 'all',resizable:true,selectOnFocus:true,
                     tpl:new Ext.XTemplate(
                       '<tpl for="."><div class="search-item">',
                       '<h3>{position_name}</h3>',
                       '</div></tpl>'
                     )
                  },'&nbsp;&nbsp;',
                  '地区','&nbsp;&nbsp;',{ref: '../marea_id',xtype: 'combo',
                     store:Mt.Test.Store.areaStoreForCombo,hiddenName : 'area_id',
                     emptyText: '请选择地区',itemSelector: 'div.search-item',
                     loadingText: '查询中...',width:100,pageSize:Mt.Test.Config.PageSize,
                     displayField:'area_name',valueField:'area_id',
                     mode: 'remote',editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                     forceSelection: true,triggerAction: 'all',resizable:true,selectOnFocus:true,
                     tpl:new Ext.XTemplate(
                       '<tpl for="."><div class="search-item">',
                       '<h3>{area_name}</h3>',
                       '</div></tpl>'
                     )
                  },'&nbsp;&nbsp;',
                  '用户名','&nbsp;&nbsp;',{ref: '../musername',width:100},'&nbsp;&nbsp;',
                  {
                    xtype : 'button',text : '查询',scope: this,
                    handler : function() {
                      this.doSelectMember();
                    }
                  },
                  {
                    xtype : 'button',text : '重置',scope: this,
                    handler : function() {
                      // this.topToolbar.mcompany_id.setValue("");
                      this.topToolbar.mdepartment_id.setValue("");
                      this.topToolbar.mposition_id.setValue("");
                      this.topToolbar.marea_id.setValue("");
                      this.topToolbar.musername.setValue("");
                      this.filter={};
                      this.doSelectMember();
                    }
                  }
                ]
              })
            ]
          },
          bbar: new Ext.PagingToolbar({
            pageSize: Mt.Test.Config.PageSize,
            store: Mt.Test.Store.selectMemberStore,
            scope:this,autoShow:true,displayInfo: true,
            displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',
            emptyMsg: "无显示数据",
            items: [
              {xtype:'label', text: '每页显示'},
              {xtype:'numberfield', value:Mt.Test.Config.PageSize,minValue:1,width:35,
                style:'text-align:center',allowBlank:false,
                listeners:
                {
                  change:function(Field, newValue, oldValue){
                    var num = parseInt(newValue);
                    if (isNaN(num) || !num || num<1)
                    {
                      num = Mt.Test.Config.PageSize;
                      Field.setValue(num);
                    }
                    Mt.Test.Config.PageSize = num;
                    this.ownerCt.ownerCt.doSelectMember();
                  },
                  specialKey :function(field,e){
                    if (e.getKey() == Ext.EventObject.ENTER){
                      var num = parseInt(field.getValue());
                      if (isNaN(num) || !num || num<1)
                      {
                        num = Mt.Test.Config.PageSize;
                      }
                      Mt.Test.Config.PageSize = num;
                      this.ownerCt.ownerCt.doSelectMember();
                    }
                  }
                }
              },
              {xtype:'label', text: '个'}
            ]
          })
        }, config);
        //初始化显示会员列表
        //this.doSelectMember();
        Mt.Test.Store.selectMemberStore.proxy=new Ext.data.DirectProxy({
          api: {read:ExtServiceTest.queryPageTestMember}
        });
        Mt.Test.View.MemberView.MemberGrid.superclass.constructor.call(this, config);
      },
      /**
      * SelectionModel
      */
      sm : new Ext.grid.CheckboxSelectionModel({
        listeners : {
          selectionchange:function(sm) {
            Mt.Test.View.Running.selectMemberWindow.changeTitle();
            Mt.Test.View.Running.selectMemberWindow.memberGrid.changeFilter();
          },
          rowselect: function(sm, rowIndex, record) {
            var selMemberWin  = Mt.Test.View.Running.selectMemberWindow;
            var selData    = selMemberWin.selData;
            var oldData    = selMemberWin.oldData;
            var member_id   = record.data.member_id;
            //添加该货品ID
            selData[member_id] = true;
            //判断是否是已关联的货品
            if(oldData[member_id]){
              oldData[member_id].active = true;
            }
          },
          rowdeselect: function(sm, rowIndex, record) {
            var selMemberWin  = Mt.Test.View.Running.selectMemberWindow;
            var selData    = selMemberWin.selData;
            var oldData    = selMemberWin.oldData;
            var member_id   = record.data.member_id;
            //删除该货品ID
            delete selData[member_id];
            //判断是否是已关联的货品
            if(oldData[member_id]){
              oldData[member_id].active = false;
            }
          }
        }
      }),
      doSelectMember : function() {
        var tmp_selMember=this.filter.selMember;
        if (this.topToolbar){
          var test_id=this.test_id;
          if (!this.filter.selectType)this.filter.selectType=0;
          // var mcompany_id = this.topToolbar.mcompany_id.getValue();
          var mdepartment_id = this.topToolbar.mdepartment_id.getValue();
          var mposition_id = this.topToolbar.mposition_id.getValue();
          var marea_id = this.topToolbar.marea_id.getValue();
          var musername = this.topToolbar.musername.getValue();
          this.filter     ={'department_id':mdepartment_id,'position_id':mposition_id,'area_id':marea_id,'username':musername,'test_id':test_id,'selectType':this.filter.selectType};
        }
        this.filter.selMember=tmp_selMember;
        var condition = {'start':0,'limit':Mt.Test.Config.PageSize};
        Ext.apply(condition,this.filter);
        ExtServiceTest.queryPageTestMember(condition,function(provider, response) {
          if (response.result&&response.result.data) {
            var result       = new Array();
            result['data']     =response.result.data;
            result['totalCount'] =response.result.totalCount;
            Mt.Test.Store.selectMemberStore.loadData(result);
          } else {
            Mt.Test.Store.selectMemberStore.removeAll();
            Ext.Msg.alert('提示', '无符合条件的会员！');
          }
        });
      },
      /**
      * 修改查询条件
      */
      changeFilter: function(){
        var selData =Mt.Test.View.Running.selectMemberWindow.selData;
        var selArr  = new Array();
        for(var x in selData){
          selArr.push(x);
        }
        this.filter.selMember = selArr.join(",");
      }
    }),
  },
  /**
   * 视图：会员考试列表
   */
  MtestView:{
  /**
   *  当前创建的会员考试编辑窗口
   */
  edit_window:null,
  /**
   * 编辑窗口：新建或者修改会员考试
   */
  EditWindow:Ext.extend(Ext.Window,{
    constructor : function(config) {
    config = Ext.apply({
      /**
       * 自定义类型:保存类型
       * 0:保存窗口,1:修改窗口
       */
      savetype:0,closeAction : "hide",constrainHeader:true,maximizable: true,collapsible: true,
      width : 450,height : 550,minWidth : 400,minHeight : 450,
      layout : 'fit',plain : true,buttonAlign : 'center',
      defaults : {autoScroll : true},
      listeners:{
      beforehide:function(){
        this.editForm.form.getEl().dom.reset();
      }
      },
      items : [
      new Ext.form.FormPanel({
        ref:'editForm',layout:'form',
        labelWidth : 100,labelAlign : "center",
        bodyStyle : 'padding:5px 5px 0',align : "center",
        api : {},
        defaults : {
        xtype : 'textfield',anchor:'98%'
        },
        items : [
                {xtype: 'hidden',name : 'mtest_id',ref:'../mtest_id'},
                {xtype: 'hidden',name : 'company_id',ref:'../company_id'},
                {
                   fieldLabel : '企业',xtype: 'combo',name : 'company_name',ref : '../company_name',
                   store:Mt.Test.Store.companyStoreForCombo,emptyText: '请选择企业',itemSelector: 'div.search-item',
                   loadingText: '查询中...',width: 570, pageSize:Mt.Test.Config.PageSize,
                   displayField:'company_name',grid:this,
                   mode: 'remote',  editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                   forceSelection: true,triggerAction: 'all',resizable:false,selectOnFocus:true,
                   tpl:new Ext.XTemplate(
                     '<tpl for="."><div class="search-item">',
                       '<h3>{company_name}</h3>',
                     '</div></tpl>'
                   ),
                   listeners:{
                     'beforequery': function(event){delete event.combo.lastQuery;}
                   },
                   onSelect:function(record,index){
                     if(this.fireEvent('beforeselect', this, record, index) !== false){
                      this.grid.company_id.setValue(record.data.company_id);
                      this.grid.company_name.setValue(record.data.company_name);
                      this.collapse();
                     }
                   }
                },
                {xtype: 'hidden',name : 'member_id',ref:'../member_id'},
                {
                   fieldLabel : '会员',xtype: 'combo',name : 'username',ref : '../username',
                   store:Mt.Test.Store.memberStoreForCombo,emptyText: '请选择会员',itemSelector: 'div.search-item',
                   loadingText: '查询中...',width: 570, pageSize:Mt.Test.Config.PageSize,
                   displayField:'username',grid:this,
                   mode: 'remote',  editable:true,minChars: 1,autoSelect :true,typeAhead: false,
                   forceSelection: true,triggerAction: 'all',resizable:false,selectOnFocus:true,
                   tpl:new Ext.XTemplate(
                     '<tpl for="."><div class="search-item">',
                       '<h3>{username}</h3>',
                     '</div></tpl>'
                   ),
                   listeners:{
                     'beforequery': function(event){delete event.combo.lastQuery;}
                   },
                   onSelect:function(record,index){
                     if(this.fireEvent('beforeselect', this, record, index) !== false){
                      this.grid.member_id.setValue(record.data.member_id);
                      this.grid.username.setValue(record.data.username);
                      this.collapse();
                     }
                   }
                },
                {xtype: 'hidden',name : 'test_id',ref:'../test_id'},
                {fieldLabel : '得分',name : 'score',xtype : 'numberfield'},
                {fieldLabel : '答案',name : 'answers_json',xtype : 'numberfield'}
        ]
      })
      ],
      buttons : [{
      text: "",ref : "../saveBtn",scope:this,
      handler : function() {

        if (!this.editForm.getForm().isValid()) {
        return;
        }
        editWindow=this;
        if (this.savetype==0){
        this.editForm.api.submit=ExtServiceMtest.save;
        this.editForm.getForm().submit({
          success : function(form, action) {
          Ext.Msg.alert("提示", "保存成功！");
          Mt.Test.View.Running.mtestGrid.doSelectMtest();
          form.reset();
          editWindow.hide();
          },
          failure : function(form, response) {
          Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
          }
        });
        }else{
        this.editForm.api.submit=ExtServiceMtest.update;
        this.editForm.getForm().submit({
          success : function(form, action) {
          Ext.Msg.show({title:'提示',msg: '修改成功！',buttons: {yes: '确定'},fn: function(){
            Mt.Test.View.Running.mtestGrid.bottomToolbar.doRefresh();
          }});
          form.reset();
          editWindow.hide();
          },
          failure : function(form, response) {
          Ext.Msg.show({title:'提示',width:350,buttons: {yes: '确定'},msg:response.result.msg});
          }
        });
        }
      }
      }, {
      text : "取 消",scope:this,
      handler : function() {
        this.hide();
      }
      }, {
      text : "重 置",ref:'../resetBtn',scope:this,
      handler : function() {
        this.editForm.form.loadRecord(Mt.Test.View.Running.mtestGrid.getSelectionModel().getSelected());

      }
      }]
    }, config);
    Mt.Test.View.MtestView.EditWindow.superclass.constructor.call(this, config);
    }
  }),
  /**
   * 查询条件
   */
  filter:null,
  /**
   * 视图：会员考试列表
   */
  Grid:Ext.extend(Ext.grid.GridPanel, {
    constructor : function(config) {
    config = Ext.apply({
      store : Mt.Test.Store.mtestStore,sm : this.sm,
      frame : true,trackMouseOver : true,enableColumnMove : true,columnLines : true,
      loadMask : true,stripeRows : true,headerAsText : false,
      defaults : {autoScroll : true},
      cm : new Ext.grid.ColumnModel({
      defaults:{
        width:120,sortable : true
      },
      columns : [
              this.sm,
              {header : '标识',dataIndex : 'mtest_id',hidden:true},
              // {header : '企业',dataIndex : 'company_name'},
              {header : '会员',dataIndex : 'username'},
              {header : '部门',dataIndex : 'department_name'},
              {header : '职位',dataIndex : 'position_name'},
              {header : '地区',dataIndex : 'area_name'},
              {header : '得分',dataIndex : 'score'}
              // {header : '答案',dataIndex : 'answers_json'}
      ]
      }),
      tbar : {
      xtype : 'container',layout : 'anchor',
      height : 27,style:'font-size:14px',
      defaults : {
        height : 27,anchor : '100%'
      },
      items : [
        new Ext.Toolbar({
        defaults:{
          scope: this
        },
        items : [
          {
          text: '反选',iconCls : 'icon-reverse',
          handler: function(){
            this.onReverseSelect();
          }
          }/*,'-',{
          text : '添加会员考试',iconCls : 'icon-add',
          handler : function() {
            this.addMtest();
          }
          },'-',{
          text : '修改会员考试',ref: '../../btnUpdate',iconCls : 'icon-edit',disabled : true,
          handler : function() {
            this.updateMtest();
          }
          },'-',{
          text : '删除会员考试', ref: '../../btnRemove',iconCls : 'icon-delete',disabled : true,
          handler : function() {
            this.deleteMtest();
          }
          }*/,'-']}
      )]
      },
      bbar: new Ext.PagingToolbar({
      pageSize: Mt.Test.Config.PageSize,
      store: Mt.Test.Store.mtestStore,scope:this,autoShow:true,displayInfo: true,
      displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',emptyMsg: "无显示数据",
      items: [
        {xtype:'label', text: '每页显示'},
        {xtype:'numberfield', value:Mt.Test.Config.PageSize,minValue:1,width:35,style:'text-align:center',allowBlank: false,
        listeners:
        {
          change:function(Field, newValue, oldValue){
          var num = parseInt(newValue);
          if (isNaN(num) || !num || num<1)
          {
            num = Mt.Test.Config.PageSize;
            Field.setValue(num);
          }
          this.ownerCt.pageSize= num;
          Mt.Test.Config.PageSize = num;
          this.ownerCt.ownerCt.doSelectMtest();
          },
          specialKey :function(field,e){
          if (e.getKey() == Ext.EventObject.ENTER){
            var num = parseInt(field.getValue());
            if (isNaN(num) || !num || num<1)num = Mt.Test.Config.PageSize;
            this.ownerCt.pageSize= num;
            Mt.Test.Config.PageSize = num;
            this.ownerCt.ownerCt.doSelectMtest();
          }
          }
        }
        },{xtype:'label', text: '个'}
      ]
      })
    }, config);
    /**
     * 会员考试数据模型获取数据Direct调用
     */
    Mt.Test.Store.mtestStore.proxy=new Ext.data.DirectProxy({
      api: {read:ExtServiceMtest.queryPageMtest}
    });
    Mt.Test.View.MtestView.Grid.superclass.constructor.call(this, config);
    },
    /**
     * 行选择器
     */
    sm : new Ext.grid.CheckboxSelectionModel({
    listeners : {
      selectionchange:function(sm) {
      // 判断删除和更新按钮是否可以激活
      this.grid.btnRemove.setDisabled(sm.getCount() < 1);
      this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
      }
    }
    }),
    /**
     * 查询符合条件的会员考试
     */
    doSelectMtest : function() {
    if (Mt.Test.View.Running.testGrid&&Mt.Test.View.Running.testGrid.getSelectionModel().getSelected()){
      var test_id = Mt.Test.View.Running.testGrid.getSelectionModel().getSelected().data.test_id;
      var condition = {'test_id':test_id,'start':0,'limit':Mt.Test.Config.PageSize};
      this.filter     ={'test_id':test_id};
      ExtServiceMtest.queryPageMtest(condition,function(provider, response) {
      if (response.result){
        if (response.result.data) {
        var result       = new Array();
        result['data']     =response.result.data;
        result['totalCount'] =response.result.totalCount;
        Mt.Test.Store.mtestStore.loadData(result);
        } else {
        Mt.Test.Store.mtestStore.removeAll();
        Ext.Msg.alert('提示', '无符合条件的会员考试！');
        }

        if (Mt.Test.Store.mtestStore.getTotalCount()>Mt.Test.Config.PageSize){
         Mt.Test.View.Running.mtestGrid.bottomToolbar.show();
        }else{
         Mt.Test.View.Running.mtestGrid.bottomToolbar.hide();
        }
        Mt.Test.View.Running.testGrid.ownerCt.doLayout();
      }
      });
    }
    },
    /**
     * 反选
     */
    onReverseSelect:function() {
    for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
      if (this.sm.isSelected(i)) {
      this.sm.deselectRow(i);
      }else {
      this.sm.selectRow(i, true);
      }
    }
    },
    /**
     * 新建会员考试
     */
    addMtest : function(){
    if (Mt.Test.View.MtestView.edit_window==null){
      Mt.Test.View.MtestView.edit_window=new Mt.Test.View.MtestView.EditWindow();
    }
    Mt.Test.View.MtestView.edit_window.resetBtn.setVisible(false);
    Mt.Test.View.MtestView.edit_window.saveBtn.setText('保 存');
    Mt.Test.View.MtestView.edit_window.setTitle('添加会员考试');
    Mt.Test.View.MtestView.edit_window.savetype=0;
    Mt.Test.View.MtestView.edit_window.mtest_id.setValue("");
    var company_id = Mt.Test.View.Running.testGrid.getSelectionModel().getSelected().data.test_id;
    Mt.Test.View.MtestView.edit_window.test_id.setValue(company_id);

    Mt.Test.View.MtestView.edit_window.show();
    Mt.Test.View.MtestView.edit_window.maximize();
    },
    /**
     * 编辑会员考试时先获得选中的会员考试信息
     */
    updateMtest : function() {
    if (Mt.Test.View.MtestView.edit_window==null){
      Mt.Test.View.MtestView.edit_window=new Mt.Test.View.MtestView.EditWindow();
    }
    Mt.Test.View.MtestView.edit_window.saveBtn.setText('修 改');
    Mt.Test.View.MtestView.edit_window.resetBtn.setVisible(true);
    Mt.Test.View.MtestView.edit_window.setTitle('修改会员考试');
    Mt.Test.View.MtestView.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
    Mt.Test.View.MtestView.edit_window.savetype=1;

    Mt.Test.View.MtestView.edit_window.show();
    Mt.Test.View.MtestView.edit_window.maximize();
    },
    /**
     * 删除会员考试
     */
    deleteMtest : function() {
    Ext.Msg.confirm('提示', '确实要删除所选的会员考试吗?', this.confirmDeleteMtest,this);
    },
    /**
     * 确认删除会员考试
     */
    confirmDeleteMtest : function(btn) {
    if (btn == 'yes') {
      var del_mtest_ids ="";
      var selectedRows  = this.getSelectionModel().getSelections();
      for ( var flag = 0; flag < selectedRows.length; flag++) {
      del_mtest_ids=del_mtest_ids+selectedRows[flag].data.mtest_id+",";
      }
      ExtServiceMtest.deleteByIds(del_mtest_ids);
      this.doSelectMtest();
      Ext.Msg.alert("提示", "删除成功！");
    }
    }
  })
  },
  /**
   * 窗口：批量上传考试
   */
  UploadWindow:Ext.extend(Ext.Window,{
  constructor : function(config) {
    config = Ext.apply({
    title : '批量上传考试数据',width : 400,height : 110,minWidth : 300,minHeight : 100,
    layout : 'fit',plain : true,bodyStyle : 'padding:5px;',buttonAlign : 'center',closeAction : "hide",
    items : [
      new Ext.form.FormPanel({
      ref:'uploadForm',fileUpload: true,
      width: 500,labelWidth: 50,autoHeight: true,baseCls: 'x-plain',
      frame:true,bodyStyle: 'padding: 10px 10px 10px 10px;',
      defaults: {
        anchor: '95%',allowBlank: false,msgTarget: 'side'
      },
      items : [{
        xtype : 'fileuploadfield',
        fieldLabel : '文 件',name : 'upload_file',ref:'upload_file',
        emptyText: '请上传考试Excel文件',buttonText: '',
        accept:'application/vnd.ms-excel',
        buttonCfg: {iconCls: 'upload-icon'}
      }]
      })
    ],
    buttons : [{
      text : '上 传',
      scope:this,
      handler : function() {
        uploadWindow       =this;
        validationExpression   =/([\u4E00-\u9FA5]|\w)+(.xlsx|.XLSX|.xls|.XLS)$/;/**允许中文名*/
        var isValidExcelFormat = new RegExp(validationExpression);
        var result       = isValidExcelFormat.test(this.uploadForm.upload_file.getValue());
        if (!result){
        Ext.Msg.alert('提示', '请上传Excel文件，后缀名为xls或者xlsx！');
        return;
        }
        if (this.uploadForm.getForm().isValid()) {
        Ext.Msg.show({
          title : '请等待',msg : '文件正在上传中，请稍后...',
          animEl : 'loading',icon : Ext.Msg.WARNING,
          closable : true,progress : true,progressText : '',width : 300
        });
        this.uploadForm.getForm().submit({
          url : 'index.php?go=admin.upload.uploadTest',
          success : function(form, response) {
          Ext.Msg.alert('成功', '上传成功');
          uploadWindow.hide();
          uploadWindow.uploadForm.upload_file.setValue('');
          Mt.Test.View.Running.testGrid.doSelectTest();
          },
          failure : function(form, response) {
          Ext.Msg.alert('错误', response.result.data);
          }
        });
        }
      }
      },{
      text : '取 消',
      scope:this,
      handler : function() {
        this.uploadForm.upload_file.setValue('');
        this.hide();
      }
      }]
    }, config);
    Mt.Test.View.UploadWindow.superclass.constructor.call(this, config);
  }
  }),
  /**
   * 视图：考试列表
   */
  Grid:Ext.extend(Ext.grid.GridPanel, {
  constructor : function(config) {
    config = Ext.apply({
    /**
     * 查询条件
     */
    filter:null,
    region : 'center',
    store : Mt.Test.Store.testStore,
    sm : this.sm,
    frame : true,trackMouseOver : true,enableColumnMove : true,columnLines : true,
    loadMask : true,stripeRows : true,headerAsText : false,
    defaults : {
      autoScroll : true
    },
    cm : new Ext.grid.ColumnModel({
      defaults:{
      width:140,sortable : true
      },
      columns : [
      this.sm,
            {header : '标识',dataIndex : 'test_id',hidden:true},
            {header : '所属用户',dataIndex : 'admin_name'},
            {header : '考试名称',dataIndex : 'test_title'},
            {header : '试卷',dataIndex : 'paper_title'},
            {header : '开考时间',dataIndex : 'begin_time',renderer:Ext.util.Format.dateRenderer('Y-m-d H:i:s')},
            {header : '交卷时间',dataIndex : 'end_time',renderer:Ext.util.Format.dateRenderer('Y-m-d H:i:s')},
            {header : '是否显示',dataIndex : 'isShow',renderer:function(value){if (value == true) {return "是";}else{return "否";}}}
      ]
    }),
    tbar : {
      xtype : 'container',layout : 'anchor',height : 27 * 2,style:'font-size:14px',
      defaults : {
      height : 27,anchor : '100%'
      },
      items : [
      new Ext.Toolbar({
        enableOverflow: true,width : 100,
        defaults : {
        xtype : 'textfield',
        listeners : {
           specialkey : function(field, e) {
          if (e.getKey() == Ext.EventObject.ENTER)this.ownerCt.ownerCt.ownerCt.doSelectTest();
          }
        }
        },
        items : [
          '考试名称','&nbsp;&nbsp;',{ref: '../ttest_title'},'&nbsp;&nbsp;',
          '试卷','&nbsp;&nbsp;',{ref: '../tpaper_id',xtype: 'combo',
             store:Mt.Test.Store.paperStoreForCombo,hiddenName : 'paper_id',
             emptyText: '请选择试卷',itemSelector: 'div.search-item',
             loadingText: '查询中...',width:180,pageSize:Mt.Test.Config.PageSize,
             displayField:'paper_title',valueField:'paper_id',
             mode: 'remote',editable:true,minChars: 1,autoSelect :true,typeAhead: false,
             forceSelection: true,triggerAction: 'all',resizable:true,selectOnFocus:true,
             tpl:new Ext.XTemplate(
               '<tpl for="."><div class="search-item">',
               '<h3>{paper_title}</h3>',
               '</div></tpl>'
             )
          } 
          ,'&nbsp;&nbsp;&nbsp;开考日期','&nbsp;&nbsp;',
          { ref:'../tbegin_time',xtype : 'datefield',format : "Y-m-d"},'&nbsp;-&nbsp;',
          { ref:'../tend_time',xtype : 'datefield',format : "Y-m-d"},
        {
          xtype : 'button',text : '查询',scope: this,
          handler : function() {
          this.doSelectTest();
          }
        },
        {
          xtype : 'button',text : '重置',scope: this,
          handler : function() {
          this.topToolbar.ttest_title.setValue("");
          this.topToolbar.tpaper_id.setValue("");
          this.topToolbar.tbegin_time.setValue("");
          this.topToolbar.tend_time.setValue("");
          this.filter={};
          this.doSelectTest();
          }
        }]
      }),
      new Ext.Toolbar({
        defaults:{scope: this},
        items : [
        {
          text: '反选',iconCls : 'icon-reverse',
          handler: function(){
          this.onReverseSelect();
          }
        },'-',{
          text : '添加考试',iconCls : 'icon-add',
          handler : function() {
          this.addTest();
          }
        },'-',{
          text : '修改考试',ref: '../../btnUpdate',iconCls : 'icon-edit',disabled : true,
          handler : function() {
          this.updateTest();
          }
        }/*,'-',{
          text : '删除考试', ref: '../../btnRemove',iconCls : 'icon-delete',disabled : true,
          handler : function() {
          this.deleteTest();
          }
        },'-',{
          xtype:'tbsplit',text: '导入', iconCls : 'icon-import',
          handler : function() {
          this.importTest();
          },
          menu: {
          xtype:'menu',plain:true,
          items: [
            {text:'批量导入考试',iconCls : 'icon-import',scope:this,handler:function(){this.importTest()}}
          ]}
        }*/,'-',{
          text : '导出考试报表',iconCls : 'icon-export',
          handler : function() {
          this.exportTest();
          }
        },'-',{
          text : '导出考试学员报表',iconCls : 'icon-export',
          handler : function() {
          this.exportMember();
          }
        },'-',{
          xtype:'tbsplit',text: '查看考试', ref:'../../tvpView',iconCls : 'icon-updown',
          enableToggle: true, disabled : true,
          handler:function(){this.showTest()},
          menu: {
          xtype:'menu',plain:true,
          items: [
            {text:'上方',group:'mlayout',checked:false,iconCls:'view-top',scope:this,handler:function(){this.onUpDown(1)}},
            {text:'下方',group:'mlayout',checked:true ,iconCls:'view-bottom',scope:this,handler:function(){this.onUpDown(2)}},
            {text:'左侧',group:'mlayout',checked:false,iconCls:'view-left',scope:this,handler:function(){this.onUpDown(3)}},
            {text:'右侧',group:'mlayout',checked:false,iconCls:'view-right',scope:this,handler:function(){this.onUpDown(4)}},
            {text:'隐藏',group:'mlayout',checked:false,iconCls:'view-hide',scope:this,handler:function(){this.hideTest();Mt.Test.Config.View.IsShow=0;}},'-',
            {text: '固定',ref:'mBind',checked: true,scope:this,checkHandler:function(item, checked){this.onBindGrid(item, checked);Mt.Test.Cookie.set('View.IsFix',Mt.Test.Config.View.IsFix);}}
          ]}
        },'-',{
                  text : '选择会员',ref:'../../tmember',iconCls : 'icon-edit',disabled : true,
                  handler : function() {
                    if(Mt.Test.View.Running.selectMemberWindow==null || Mt.Test.View.Running.selectMemberWindow.hidden){
                      this.showMember();
                    }else{
                      this.hideMember();
                    }
                  }
                },'-']}
      )]
    },
    bbar: new Ext.PagingToolbar({
      pageSize: Mt.Test.Config.PageSize,
      store: Mt.Test.Store.testStore,
      scope:this,autoShow:true,displayInfo: true,
      displayMsg: '当前显示 {0} - {1}条记录/共 {2}条记录。',
      emptyMsg: "无显示数据",
      listeners:{
      change:function(thisbar,pagedata){
        if (Mt.Test.Viewport){
        if (Mt.Test.Config.View.IsShow==1){
          Mt.Test.View.IsSelectView=1;
        }
        this.ownerCt.hideTest();
        Mt.Test.Config.View.IsShow=0;
        }
      }
      },
      items: [
      {xtype:'label', text: '每页显示'},
      {xtype:'numberfield', value:Mt.Test.Config.PageSize,minValue:1,width:35,
        style:'text-align:center',allowBlank: false,
        listeners:
        {
        change:function(Field, newValue, oldValue){
          var num = parseInt(newValue);
          if (isNaN(num) || !num || num<1)
          {
          num = Mt.Test.Config.PageSize;
          Field.setValue(num);
          }
          this.ownerCt.pageSize= num;
          Mt.Test.Config.PageSize = num;
          this.ownerCt.ownerCt.doSelectTest();
        },
        specialKey :function(field,e){
          if (e.getKey() == Ext.EventObject.ENTER){
          var num = parseInt(field.getValue());
          if (isNaN(num) || !num || num<1)
          {
            num = Mt.Test.Config.PageSize;
          }
          this.ownerCt.pageSize= num;
          Mt.Test.Config.PageSize = num;
          this.ownerCt.ownerCt.doSelectTest();
          }
        }
        }
      },
      {xtype:'label', text: '个'}
      ]
    })
    }, config);
    //初始化显示考试列表
    this.doSelectTest();
    Mt.Test.View.Grid.superclass.constructor.call(this, config);
    //创建在Grid里显示的考试信息Tab页
    Mt.Test.View.Running.viewTabs=new Mt.Test.View.TestView.Tabs();
    this.addListener('rowdblclick', this.onRowDoubleClick);
  },
  /**
   * 行选择器
   */
  sm : new Ext.grid.CheckboxSelectionModel({
    //handleMouseDown : Ext.emptyFn,
    listeners : {
    selectionchange:function(sm) {
      // 判断删除和更新按钮是否可以激活
      // this.grid.btnRemove.setDisabled(sm.getCount() < 1);
      this.grid.btnUpdate.setDisabled(sm.getCount() != 1);
      this.grid.tvpView.setDisabled(sm.getCount() != 1);
          this.grid.tmember.setDisabled(sm.getCount() != 1);
    },
    rowselect: function(sm, rowIndex, record) {
      if (sm.getCount() != 1){
      this.grid.hideTest();
      Mt.Test.Config.View.IsShow=0;
            this.grid.hideMember();
      }else{
      if (Mt.Test.View.IsSelectView==1){
        Mt.Test.View.IsSelectView=0;
        this.grid.showTest();
      }
      }
    },
    rowdeselect: function(sm, rowIndex, record) {
      if (sm.getCount() != 1){
      if (Mt.Test.Config.View.IsShow==1){
        Mt.Test.View.IsSelectView=1;
      }
      this.grid.hideTest();
      Mt.Test.Config.View.IsShow=0;
      }
    }
    }
  }),
  /**
   * 双击选行
   */
  onRowDoubleClick:function(grid, rowIndex, e){
    if (!Mt.Test.Config.View.IsShow){
    this.sm.selectRow(rowIndex);
    this.showTest();
    this.tvpView.toggle(true);
    }else{
    this.hideTest();
    Mt.Test.Config.View.IsShow=0;
    this.sm.deselectRow(rowIndex);
    this.tvpView.toggle(false);
    }
  },
  /**
   * 是否绑定在本窗口上
   */
  onBindGrid:function(item, checked){
    if (checked){
     Mt.Test.Config.View.IsFix=1;
    }else{
     Mt.Test.Config.View.IsFix=0;
    }
    if (this.getSelectionModel().getSelected()==null){
    Mt.Test.Config.View.IsShow=0;
    return ;
    }
    if (Mt.Test.Config.View.IsShow==1){
     this.hideTest();
     Mt.Test.Config.View.IsShow=0;
    }
    this.showTest();
  },
  /**
   * 反选
   */
  onReverseSelect:function() {
    for (var i = this.getView().getRows().length - 1; i >= 0; i--) {
    if (this.sm.isSelected(i)) {
      this.sm.deselectRow(i);
    }else {
      this.sm.selectRow(i, true);
    }
    }
  },
  /**
   * 查询符合条件的考试
   */
  doSelectTest : function() {
    if (this.topToolbar){
        var ttest_title = this.topToolbar.ttest_title.getValue();
        var tpaper_id = this.topToolbar.tpaper_id.getValue();
        var tbegin_time = this.topToolbar.tbegin_time.getValue();
        var tend_time = this.topToolbar.tend_time.getValue();

        this.filter     ={'test_title':ttest_title,'paper_id':tpaper_id,'begin_time':tbegin_time,'end_time':tend_time};
    }
    var condition = {'start':0,'limit':Mt.Test.Config.PageSize};
    Ext.apply(condition,this.filter);
    ExtServiceTest.queryPageTest(condition,function(provider, response) {
    if (response.result&&response.result.data) {
      var result       = new Array();
      result['data']     =response.result.data;
      result['totalCount'] =response.result.totalCount;
      Mt.Test.Store.testStore.loadData(result);
    } else {
      Mt.Test.Store.testStore.removeAll();
      Ext.Msg.alert('提示', '无符合条件的考试！');
    }
    });
  },
  /**
   * 显示考试视图
   * 显示考试的视图相对考试列表Grid的位置
   * 1:上方,2:下方,0:隐藏。
   */
  onUpDown:function(viewDirection){
    Mt.Test.Config.View.Direction=viewDirection;
    switch(viewDirection){
    case 1:
      this.ownerCt.north.add(Mt.Test.View.Running.viewTabs);
      break;
    case 2:
      this.ownerCt.south.add(Mt.Test.View.Running.viewTabs);
      break;
    case 3:
      this.ownerCt.west.add(Mt.Test.View.Running.viewTabs);
      break;
    case 4:
      this.ownerCt.east.add(Mt.Test.View.Running.viewTabs);
      break;
    }
    Mt.Test.Cookie.set('View.Direction',Mt.Test.Config.View.Direction);
    if (this.getSelectionModel().getSelected()!=null){
    if ((Mt.Test.Config.View.IsFix==0)&&(Mt.Test.Config.View.IsShow==1)){
      this.showTest();
    }
    Mt.Test.Config.View.IsFix=1;
    Mt.Test.View.Running.testGrid.tvpView.menu.mBind.setChecked(true,true);
    Mt.Test.Config.View.IsShow=0;
    this.showTest();
    }
  },
  /**
   * 显示考试
   */
  showTest : function(){
    if (this.getSelectionModel().getSelected()==null){
    Ext.Msg.alert('提示', '请先选择考试！');
    Mt.Test.Config.View.IsShow=0;
    this.tvpView.toggle(false);
    return ;
    }
    if (Mt.Test.Config.View.IsFix==0){
    if (Mt.Test.View.Running.view_window==null){
      Mt.Test.View.Running.view_window=new Mt.Test.View.TestView.Window();
    }
    if (Mt.Test.View.Running.view_window.hidden){
      Mt.Test.View.Running.view_window.show();
      Mt.Test.View.Running.view_window.winTabs.hideTabStripItem(Mt.Test.View.Running.view_window.winTabs.tabFix);
      this.updateViewTest();
      this.tvpView.toggle(true);
      Mt.Test.Config.View.IsShow=1;
    }else{
      this.hideTest();
      Mt.Test.Config.View.IsShow=0;
    }
    return;
    }
    switch(Mt.Test.Config.View.Direction){
    case 1:
      if (!this.ownerCt.north.items.contains(Mt.Test.View.Running.viewTabs)){
      this.ownerCt.north.add(Mt.Test.View.Running.viewTabs);
      }
      break;
    case 2:
      if (!this.ownerCt.south.items.contains(Mt.Test.View.Running.viewTabs)){
      this.ownerCt.south.add(Mt.Test.View.Running.viewTabs);
      }
      break;
    case 3:
      if (!this.ownerCt.west.items.contains(Mt.Test.View.Running.viewTabs)){
      this.ownerCt.west.add(Mt.Test.View.Running.viewTabs);
      }
      break;
    case 4:
      if (!this.ownerCt.east.items.contains(Mt.Test.View.Running.viewTabs)){
      this.ownerCt.east.add(Mt.Test.View.Running.viewTabs);
      }
      break;
    }
    this.hideTest();
    if (Mt.Test.Config.View.IsShow==0){
    Mt.Test.View.Running.viewTabs.enableCollapse();
    switch(Mt.Test.Config.View.Direction){
      case 1:
      this.ownerCt.north.show();
      break;
      case 2:
      this.ownerCt.south.show();
      break;
      case 3:
      this.ownerCt.west.show();
      break;
      case 4:
      this.ownerCt.east.show();
      break;
    }
    this.updateViewTest();
    this.tvpView.toggle(true);
    Mt.Test.Config.View.IsShow=1;
    }else{
    Mt.Test.Config.View.IsShow=0;
    }
    this.ownerCt.doLayout();
  },
  /**
   * 隐藏考试
   */
  hideTest : function(){
    this.ownerCt.north.hide();
    this.ownerCt.south.hide();
    this.ownerCt.west.hide();
    this.ownerCt.east.hide();
    if (Mt.Test.View.Running.view_window!=null){
    Mt.Test.View.Running.view_window.hide();
    }
    this.tvpView.toggle(false);
    this.ownerCt.doLayout();
  },
  /**
   * 更新当前考试显示信息
   */
  updateViewTest : function() {
      Mt.Test.View.Running.mtestGrid.doSelectMtest();
    if (Mt.Test.View.Running.view_window!=null){
    Mt.Test.View.Running.view_window.winTabs.tabTestDetail.update(this.getSelectionModel().getSelected().data);
    }
    Mt.Test.View.Running.viewTabs.tabTestDetail.update(this.getSelectionModel().getSelected().data);
  },
  /**
   * 新建考试
   */
  addTest : function() {
    if (Mt.Test.View.Running.edit_window==null){
    Mt.Test.View.Running.edit_window=new Mt.Test.View.EditWindow();
    }
    Mt.Test.View.Running.edit_window.resetBtn.setVisible(false);
    Mt.Test.View.Running.edit_window.saveBtn.setText('保 存');
    Mt.Test.View.Running.edit_window.setTitle('添加考试');
    Mt.Test.View.Running.edit_window.savetype=0;
    Mt.Test.View.Running.edit_window.test_id.setValue("");
      // switch (Mt.Test.Config.OnlineEditor)
      // {
      //   case 2:
      //     if (Mt.Test.View.EditWindow.KindEditor_paper_json) Mt.Test.View.EditWindow.KindEditor_paper_json.html("");
      //     break
      //   case 3:
      //     break
      //   default:
      //     if (CKEDITOR.instances.paper_json) CKEDITOR.instances.paper_json.setData("");
      // }

    Mt.Test.View.Running.edit_window.show();
    Mt.Test.View.Running.edit_window.maximize();
  },
  /**
   * 编辑考试时先获得选中的考试信息
   */
  updateTest : function() {
    if (Mt.Test.View.Running.edit_window==null){
    Mt.Test.View.Running.edit_window=new Mt.Test.View.EditWindow();
    }
    Mt.Test.View.Running.edit_window.saveBtn.setText('修 改');
    Mt.Test.View.Running.edit_window.resetBtn.setVisible(true);
    Mt.Test.View.Running.edit_window.setTitle('修改考试');
    Mt.Test.View.Running.edit_window.editForm.form.loadRecord(this.getSelectionModel().getSelected());
    Mt.Test.View.Running.edit_window.savetype=1;
      // switch (Mt.Test.Config.OnlineEditor)
      // {
      //   case 2:
      //     if (Mt.Test.View.EditWindow.KindEditor_paper_json) Mt.Test.View.EditWindow.KindEditor_paper_json.html(this.getSelectionModel().getSelected().data.paper_json);
      //     break
      //   case 3:
      //     if (xhEditor_paper_json)xhEditor_paper_json.setSource(this.getSelectionModel().getSelected().data.paper_json);
      //     break
      //   default:
      //     if (CKEDITOR.instances.paper_json) CKEDITOR.instances.paper_json.setData(this.getSelectionModel().getSelected().data.paper_json);
      // }

    Mt.Test.View.Running.edit_window.show();
    Mt.Test.View.Running.edit_window.maximize();
  },
  /**
   * 删除考试
   */
  deleteTest : function() {
    Ext.Msg.confirm('提示', '确实要删除所选的考试吗?', this.confirmDeleteTest,this);
  },
  /**
   * 确认删除考试
   */
  confirmDeleteTest : function(btn) {
    if (btn == 'yes') {
    var del_test_ids ="";
    var selectedRows  = this.getSelectionModel().getSelections();
    for ( var flag = 0; flag < selectedRows.length; flag++) {
      del_test_ids=del_test_ids+selectedRows[flag].data.test_id+",";
    }
    ExtServiceTest.deleteByIds(del_test_ids);
    this.doSelectTest();
    Ext.Msg.alert("提示", "删除成功！");
    }
  },
    /**
     * 显示会员
     */
    showMember:function(){
      if (Mt.Test.View.Running.selectMemberWindow==null){
        Mt.Test.View.Running.selectMemberWindow=new Mt.Test.View.MemberView.SelectMemberWindow();
      }
      var test_id=Mt.Test.View.Running.testGrid.getSelectionModel().getSelected().data.test_id;

      //关联会员ID组成的字符串
      var memberStr  = Mt.Test.View.Running.testGrid.getSelectionModel().getSelected().data.memberStr;
      var selData  = {};
      var oldData  = {};
      if(memberStr){
        var memberArr = memberStr.split(",");
        for(var i=0;i<memberArr.length;i++){
          selData[memberArr[i]] = true;//ture为已存在的关联货品
          oldData[memberArr[i]] = {};
          oldData[memberArr[i]].active = true;
        }
      }
      var selMemberWin   = Mt.Test.View.Running.selectMemberWindow;
      var selMemberGrid  = selMemberWin.memberGrid;
      selMemberWin.selData = selData;
      selMemberWin.oldData = oldData;
      selMemberWin.changeTitle();//根据选择的货品,修改标题

      selMemberGrid.test_id = test_id;
      if (selMemberWin.hidden){
        // Mt.Test.View.Running.selectMemberWindow.memberGrid.topToolbar.mcompany_id.setValue("");
        Mt.Test.View.Running.selectMemberWindow.memberGrid.topToolbar.mdepartment_id.setValue("");
        Mt.Test.View.Running.selectMemberWindow.memberGrid.topToolbar.mposition_id.setValue("");
        Mt.Test.View.Running.selectMemberWindow.memberGrid.topToolbar.marea_id.setValue("");
        Mt.Test.View.Running.selectMemberWindow.memberGrid.topToolbar.musername.setValue("");
        selMemberGrid.filter = {selMember:memberStr};
        selMemberGrid.topToolbar.menus.all.setChecked(true);
        selMemberGrid.isSelect.toggle(false);
        Mt.Test.Store.selectMemberStore.removeAll();
      }
      selMemberGrid.doSelectMember();
      selMemberWin.show();
    },
    /**
     * 隐藏会员
     */
    hideMember:function(){
      if (Mt.Test.View.Running.selectMemberWindow!=null){
        Mt.Test.View.Running.selectMemberWindow.hide();
      }
    },
  /**
   * 导出考试报表
   */
  exportTest : function() {
    ExtServiceTest.exportTest(this.filter,function(provider, response) {
    if (response.result.data) {
      window.open(response.result.data);
    }
    });
  },
  /**
   * 导出课程学员报表
   */
  exportMember : function() {
    ExtServiceTest.exportMember(this.filter,function(provider, response) {
      if (response.result.data) {
        window.open(response.result.data);
      }
    });
  },
  /**
   * 导入考试
   */
  importTest : function() {
    if (Mt.Test.View.current_uploadWindow==null){
    Mt.Test.View.current_uploadWindow=new Mt.Test.View.UploadWindow();
    }
    Mt.Test.View.current_uploadWindow.show();
  }
  }),
  /**
   * 核心内容区
   */
  Panel:Ext.extend(Ext.form.FormPanel,{
  constructor : function(config) {
    Mt.Test.View.Running.testGrid=new Mt.Test.View.Grid();
    if (Mt.Test.Config.View.IsFix==0){
    Mt.Test.View.Running.testGrid.tvpView.menu.mBind.setChecked(false,true);
    }
    config = Ext.apply({
    region : 'center',layout : 'fit', frame:true,
    items: {
      layout:'border',
      items:[
      Mt.Test.View.Running.testGrid,
      {region:'north',ref:'north',layout:'fit',collapseMode : 'mini',border:false,split: true,hidden:true},
      {region:'south',ref:'south',layout:'fit',collapseMode : 'mini',border:false,split: true,hidden:true,items:[Mt.Test.View.Running.viewTabs]},
      {region:'west',ref:'west',layout:'fit',collapseMode : 'mini',border:false,split: true,hidden:true},
      {region:'east',ref:'east',layout:'fit',collapseMode : 'mini',border:false,split: true,hidden:true}
      ]
    }
    }, config);
    Mt.Test.View.Panel.superclass.constructor.call(this, config);
  }
  }),
  /**
   * 当前运行的可视化对象
   */
  Running:{
  /**
   * 当前考试Grid对象
   */
  testGrid:null,
    /**
     * 当前会员考试Grid对象
     */
    mtestGrid:null,
    /**
     * 推荐会员
     */
    selectMemberWindow:null,
  /**
   * 显示考试信息及关联信息列表的Tab页
   */
  viewTabs:null,
  /**
   * 当前创建的编辑窗口
   */
  edit_window:null,
  /**
   * 当前的显示窗口
   */
  view_window:null
  }
};
/**
 * Controller:主程序
 */
Ext.onReady(function(){
  Ext.QuickTips.init();
  Ext.state.Manager.setProvider(Mt.Test.Cookie);
  Ext.Direct.addProvider(Ext.app.REMOTING_API);
  Mt.Test.Init();
  /**
   * 考试数据模型获取数据Direct调用
   */
  Mt.Test.Store.testStore.proxy=new Ext.data.DirectProxy({
  api: {read:ExtServiceTest.queryPageTest}
  });
  /**
   * 考试页面布局
   */
  Mt.Test.Viewport = new Ext.Viewport({
  layout : 'border',
  items : [new Mt.Test.View.Panel()]
  });
  Mt.Test.Viewport.doLayout();
  setTimeout(function(){
  Ext.get('loading').remove();
  Ext.get('loading-mask').fadeOut({
    remove:true
  });
  }, 250);
});